﻿using System;
using Glue;
using Xunit;

namespace GlueExamples
{
    namespace RelationsVerification
    {
        public class When_a_relation_is_only_one_direction
        {
            private readonly Mapping<DomainPerson, GuiPerson> mapping;
            private readonly IRelationsVerification verification;

            private class DomainPerson { public String FirstName { get; set; } }
            private class GuiPerson { public String FirstName { get; set; } }

            public When_a_relation_is_only_one_direction()
            {
                mapping = new Mapping<DomainPerson, GuiPerson>();
                mapping.RelateTowardsLeft(domain => domain.FirstName, gui => gui.FirstName);
                verification = mapping.GetRelationsVerification();
            }

            [Fact]
            public void Should_verify_the_relation_direction()
            {
                verification.AssertAllPropertiesRelated<DomainPerson>();
            }

            [Fact]
            public void Should_not_verify_the_other_direction()
            {
                Assert.Throws(typeof(GlueException), () => verification.AssertAllPropertiesRelated<GuiPerson>());
            }

            [Fact]
            public void Should_verify_the_other_direction_if_that_direction_is_ignored()
            {
                mapping.IgnoreTowards<GuiPerson>(gui => gui.FirstName);
                verification.AssertAllPropertiesRelated<GuiPerson>();
            }
        }
    }
}
